﻿//// <copyright file="App.xaml.cs" company="company"> 
//// (C) 2010 . All rights reserved
//// </copyright>
//// <author>Lukasz Bartczak</author>

namespace SecretaryAppNav
{
    using System.Windows;
    using System.Windows.Controls;

    ///// <summary>
    ///// App partial class implementing from <see cref="Application" /> class.
    ///// </summary>
    public partial class App : Application
    {
        ///// <summary>
        ///// Initializes a new instance of the <see cref="App"/> class.
        ///// </summary>
        public App()
        {
            this.Startup += this.Application_Startup;
            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();
        }

        ///// <summary>
        ///// Handles the Startup event of the Application control.
        ///// </summary>
        ///// <param name="sender">The source of the event.</param>
        ///// <param name="e">The <see cref="System.Windows.StartupEventArgs"/> instance containing the event data.</param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();
        }

        ///// <summary>
        ///// Handles the UnhandledException event of the Application control.
        ///// </summary>
        ///// <param name="sender">The source of the event.</param>
        ///// <param name="e">The <see cref="System.Windows.ApplicationUnhandledExceptionEventArgs"/> instance containing the event data.</param>
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            //// If the app is running outside of the debugger then report the exception using
            //// a ChildWindow control.
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                //// NOTE: This will allow the application to continue running after an exception has been thrown
                //// but not handled. 
                //// For production applications this error handling should be replaced with something that will 
                //// report the error to the website and stop the application.
                e.Handled = true;
                ChildWindow errorWin = new ErrorWindow(e.ExceptionObject.InnerException);
                errorWin.Show();
            }
        }
    }
}